package com.pbd.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.pbd.client.tag.TagCloud;
import com.pbd.client.tag.WordTag;
import com.pbd.client.utils.LoadingBox;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class PBD implements EntryPoint {
	// private Image leftImage;
	private VerticalPanel vpSearchMember;
	private FlexTable topMenuTable;
	private GoogleMap googlePopup;

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		FlexTable topPanel = new FlexTable();
		// topPanel.setBorderWidth(2);
		topPanel.setWidth("960px");
		topPanel.setWidget(0, 0, getEmptyHTML());
		topPanel.setWidget(0, 1, getEmptyHTML());
		topPanel.setWidget(1, 0, new Image("./images/PBL_logo.png"));
		vpSearchMember = new VerticalPanel();
		topMenuTable = new FlexTable();
		topMenuTable.setCellPadding(0);
		topMenuTable.setCellSpacing(0);
		topMenuTable.setWidth("660px");
		topPanel.setWidget(1, 1, topMenuTable);
		addTopMenus();

		FlexTable searchTable = new FlexTable();
		searchTable.setWidth("500px");
		searchTable.setStyleName("searchGrid");
		searchTable.setCellPadding(0);
		searchTable.setCellSpacing(0);
		topPanel.setWidget(2, 0, searchTable);
		addSearchComponent(searchTable);

		topPanel.getFlexCellFormatter().setStyleName(2, 0, "searchGrid");
		topPanel.getFlexCellFormatter().setWidth(2, 0, "680px");
		topPanel.getFlexCellFormatter().setRowSpan(1, 0, 2);
		topPanel.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		topPanel.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
		topPanel.getFlexCellFormatter().setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_BOTTOM);
		topPanel.getFlexCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);
		topPanel.getFlexCellFormatter().setHeight(2, 0, "138px");
		topPanel.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		topPanel.getFlexCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);
		RootPanel.get("headerContainer").add(topPanel);

		FlexTable mainPanel = new FlexTable();
		mainPanel.setWidth("960px");
		RootPanel.get("mainContainer").add(mainPanel);
		addMainContainter(mainPanel);

		FlexTable bottomPanel = new FlexTable();
		bottomPanel.setWidth("100%");
		bottomPanel.setHeight("50px");
		bottomPanel.setStyleName("footer_bg");
		RootPanel.get("footerContainer").add(bottomPanel);

		FlexTable bottmMenuTable = new FlexTable();
		bottmMenuTable.setCellPadding(0);
		bottmMenuTable.setCellSpacing(0);
		bottmMenuTable.setWidth("450px");
		bottomPanel.setWidget(0, 1, bottmMenuTable);
		bottomPanel.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
		bottomPanel.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_BOTTOM);
		addBottomMenus(bottmMenuTable);

	}

	private void addMainContainter(FlexTable mainTable) {

		FlexTable ftLeftBlue = new FlexTable();
		ftLeftBlue.setStyleName("left_blue_box");
		ftLeftBlue.setWidth("334px");
		ftLeftBlue.setHeight("450px");

		ftLeftBlue.setWidget(0, 0, new HTML("What do we offer?"));
		ftLeftBlue.setWidget(1, 0, new HTML("BUSINESS WEB DIRECTORY"));
		ftLeftBlue.setWidget(2, 0, new HTML("Much has been made lately about the usefulness of submitting to web directories. This mechanism helps to get you the widest possible number of visitors and thus expand your name and brand. There are two ways to use web directories. The first of course is to submit your site to them for broadcast. The other is to search through web directories for sites that fit your needs."));
		ftLeftBlue.setWidget(3, 0, new HTML("PRECISE RESEARCH"));
		ftLeftBlue.setWidget(4, 0, new HTML("Given today's lifestyles, finding time to locate appropriate information can be time consuming. At professionalbuilderdirectory.com, the legwork has already been done for you - each link is thoroughly researched and must adhere to a strict and demanding criteria of information fluency and currently."));
		ftLeftBlue.setWidget(5, 0, new HTML("EXPERIENCED EDITIORS"));
		ftLeftBlue.setWidget(6, 0, new HTML("         To insure that you have dependable access to the most current and reliable information, each category is developed, organized, reviewed, and carefully maintained by individuals with research expertise in building industry"));
		ftLeftBlue.getFlexCellFormatter().setStyleName(0, 0, "heading_blue");
		ftLeftBlue.getFlexCellFormatter().setStyleName(1, 0, "heading_blue1");
		ftLeftBlue.getFlexCellFormatter().setStyleName(2, 0, "body_txt_black");
		ftLeftBlue.getFlexCellFormatter().setStyleName(3, 0, "heading_blue1");
		ftLeftBlue.getFlexCellFormatter().setStyleName(4, 0, "body_txt_black");
		ftLeftBlue.getFlexCellFormatter().setStyleName(5, 0, "heading_blue1");
		ftLeftBlue.getFlexCellFormatter().setStyleName(6, 0, "body_txt_black");
		mainTable.setWidget(0, 0, ftLeftBlue);

		FlexTable hpBusinessImages = new FlexTable();
		hpBusinessImages.setStyleName("left_blue_box1");
		hpBusinessImages.setWidth("600px");
		mainTable.setWidget(0, 1, hpBusinessImages);

		Image leftImage = new Image("./images/left_arrow_02.gif");
		Image rightImage = new Image("./images/right_arrow_01.gif");
		FlexTable childBusinessTable = new FlexTable();
		childBusinessTable.setWidget(0, 0, leftImage);
		childBusinessTable.setWidget(0, 1, new HTML());
		childBusinessTable.setWidget(0, 2, new HTML());
		childBusinessTable.setWidget(0, 3, new HTML());
		childBusinessTable.setWidget(0, 4, new HTML());
		childBusinessTable.setWidget(0, 5, new HTML());
		childBusinessTable.setWidget(0, 6, rightImage);

		hpBusinessImages.setWidget(0, 0, childBusinessTable);

		childBusinessTable.getFlexCellFormatter().setStyleName(0, 1, "Prem_AD_box");
		childBusinessTable.getFlexCellFormatter().setStyleName(0, 3, "Prem_AD_box");
		childBusinessTable.getFlexCellFormatter().setStyleName(0, 5, "Prem_AD_box");

		childBusinessTable.getFlexCellFormatter().setWidth(0, 2, "15x");
		childBusinessTable.getFlexCellFormatter().setWidth(0, 4, "15px");

		// childBusinessTable.getFlexCellFormatter().setWidth(0, 1, "188px");
		// childBusinessTable.getFlexCellFormatter().setWidth(0, 3, "188px");
		// childBusinessTable.getFlexCellFormatter().setWidth(0, 5, "188px");
		addImages(childBusinessTable, leftImage, rightImage, "BusinessImages", 3, "100px", "150px");

		mainTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		mainTable.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
		mainTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
		mainTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);

		FlexTable quickBusSearhTable = new FlexTable();
		quickBusSearhTable.setStyleName("left_blue_box");
		mainTable.setWidget(1, 0, quickBusSearhTable);

		mainTable.setWidget(2, 0, vpSearchMember);
		mainTable.getFlexCellFormatter().setRowSpan(0, 0, 3);
		mainTable.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
		mainTable.getFlexCellFormatter().setWidth(1, 0, "550px");
		mainTable.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
		addBusinessCategory(quickBusSearhTable);

	}

	private void addBusinessCategory(final FlexTable quickBusSearhTable) {
		final FlexTable subTable = new FlexTable();
		subTable.setWidget(0, 0, new HTML("Business Category"));
		subTable.getFlexCellFormatter().setStyleName(0, 0, "heading_blue_s");
		quickBusSearhTable.setWidget(0, 0, subTable);
		// subTable.getFlexCellFormatter().setWidth(0, 0, "550px");
		LoadingBox.getSharedInstance().show();
		ServiceUtil.getHibernateServiceAsync().findObjects("BUSINESSCATEGORYRELATION", new String[] { "businessCategory.id", "businessCategory.name" }, "BUSINESSCATEGORY.isActive=true AND BUSINESSCATEGORY.isPrimary=true AND PARTY.isActive=true", new String[] { "businessCategory.id", "party.partyId" }, new AsyncCallback() {

			@Override
			public void onFailure(Throwable caught) {
				LoadingBox.getSharedInstance().hide();
				//Window.alert("addBusinessCategory.quicksearch:"+caught.getLocalizedMessage());

			}

			@Override
			public void onSuccess(Object result) {
				LoadingBox.getSharedInstance().hide();
				List dataList = (List) result;
				Iterator iterator = dataList.iterator();
				List wordTagList = new ArrayList();
				while (iterator.hasNext()) {
					ArrayList dataValueList = (ArrayList) iterator.next();
					wordTagList.add(new WordTag((Long) dataValueList.get(0), (String) dataValueList.get(1), "Business Category"));
				}
				TagCloud tagCloud = new TagCloud();
				tagCloud.populate(wordTagList);
				tagCloud.setColored(true);
				subTable.setWidget(1, 0, tagCloud);
				subTable.getFlexCellFormatter().setStyleName(1, 0, "center_white_box");

			}
		});
	}

	private void addSearchComponent(FlexTable searchTable) {
		HTML htmlSearchBusAdd = new HTML("<td width=\"24px\" height=\"24px\"><img align=\"left\" valign=\"middle\" src=./images/search_icon.png></img></td><td valign=\"middle\"> Search a Business Ad.</td>");
		htmlSearchBusAdd.setStyleName("heading_white");
		searchTable.setWidget(0, 0, htmlSearchBusAdd);

		Label lblmemberName = new Label("Name");
		lblmemberName.setStyleName("body_txt_white");
		searchTable.setWidget(1, 0, lblmemberName);

		Label lblBusCategory = new Label("Business category");
		lblBusCategory.setStyleName("body_txt_white");
		searchTable.setWidget(1, 1, lblBusCategory);

		final TextBox tbMemberName = new TextBox();
		tbMemberName.setStyleName("inputstyle");
		searchTable.setWidget(2, 0, tbMemberName);
		MultiWordSuggestOracle bcMWSuggestOracle = new MultiWordSuggestOracle();
		final SuggestBox sbBusinessCategory = new SuggestBox(bcMWSuggestOracle);
		sbBusinessCategory.setWidth("195px");
		sbBusinessCategory.setHeight("12px");
		searchTable.setWidget(2, 1, sbBusinessCategory);
		populateBusinessCategory(bcMWSuggestOracle);
		Label lblKeyWord = new Label("Keywords");
		lblKeyWord.setStyleName("body_txt_white");
		searchTable.setWidget(3, 0, lblKeyWord);

		Label lblLocation = new Label("Location");
		lblLocation.setStyleName("body_txt_white");
		searchTable.setWidget(3, 1, lblLocation);

		final TextBox tbKeyWords = new TextBox();
		tbKeyWords.setStyleName("inputstyle");
		searchTable.setWidget(4, 0, tbKeyWords);

		MultiWordSuggestOracle locMWSuggestOracle = new MultiWordSuggestOracle();
		final SuggestBox sbLocation = new SuggestBox(locMWSuggestOracle);
		populateArea(locMWSuggestOracle, "Chennai", sbLocation, "");
		sbLocation.setWidth("195px");
		sbLocation.setHeight("12px");
		searchTable.setWidget(4, 1, sbLocation);
		Image searchButton = new Image("./images/search_bt.png");
		searchTable.setWidget(2, 2, searchButton);
		searchButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				String whereClause = getSearchCriteria(tbMemberName, sbBusinessCategory, tbKeyWords, sbLocation);
				if (whereClause.trim().length() == 0) {
					Window.alert("Select any search criteria");
					return;
				}

				List<String> filterAndOrderExtraColumnsList = new ArrayList<String>();

				if (sbBusinessCategory.getText() != null && sbBusinessCategory.getText().length() > 0)
					filterAndOrderExtraColumnsList.add("businessCategoryRelation.businessCategory.id");

				if (sbLocation.getText() != null && sbLocation.getText().length() > 0)
					filterAndOrderExtraColumnsList.add("partyContacts.partyContactId");
				if (vpSearchMember.getWidgetCount() > 0)
					vpSearchMember.clear();
				String[] filterAndOrderExtraColumnsExp = (String[]) filterAndOrderExtraColumnsList.toArray(new String[0]);

				FlexTable mainTable = (FlexTable) RootPanel.get("mainContainer").getWidget(0);
				mainTable.clear();
				mainTable.setCellSpacing(8);
				LoadingBox.getSharedInstance().show();
				mainTable.setWidget(0, 0, new MemberSearchGrid(whereClause, filterAndOrderExtraColumnsExp));

				FlexTable adsTable = new FlexTable();
				adsTable.setStyleName("gray_box");
				adsTable.setWidth("250px");
				adsTable.setHeight("607px");
				adsTable.setWidget(0, 0, new HTML("<p><span class=\"body_txt_black\"></span><span class=\"heading_blue_s2\"><br></span><span class=\"heading_blue\">ADVERTISE<br>YOUR<br>BUSINESS</span><span class=\"body_txt_black1\"><br><br></span><span class=\"heading_orange\"><font color=\"#00e1ff\" size=\"+4\"><b>HERE</b></font></span><br><br></p><p class=\"heading_orange1\"><span class=\"body_txt_black\">Please Contact:</span><br><img src=\".\\images\\phone_icon.png\"/>&nbsp&nbsp<span class=\"heading_orange1\">6529 1930 / 2235 0986</span></p>"));
				mainTable.setWidget(0, 1, adsTable);
				mainTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);
				// mainTable.getFlexCellFormatter().setWidth(0, 1, "200px");
				// mainTable.getFlexCellFormatter().setHeight(0, 1, "607px");
				// mainTable.getFlexCellFormatter().setStyleName(0, 1,
				// "gray_box");
			}
		});
		
		searchTable.getFlexCellFormatter().setRowSpan(2, 2, 5);
		searchTable.getFlexCellFormatter().setVerticalAlignment(2, 2, HasVerticalAlignment.ALIGN_MIDDLE);
		searchTable.getFlexCellFormatter().setWidth(1, 0, "220px");
		searchTable.getFlexCellFormatter().setWidth(1, 1, "220px");
		searchTable.getFlexCellFormatter().setWidth(1, 2, "60px");
		// searchTable.getFlexCellFormatter().setWidth(2, 1, "220px");
		// searchTable.getFlexCellFormatter().setWidth(4, 1, "220px");

		searchTable.getFlexCellFormatter().setColSpan(0, 1, 2);

	}

	private String getSearchCriteria(TextBox tbMemberName, SuggestBox sbBusinessCategory, TextBox tbKeyWords, SuggestBox sbLocation) {
		StringBuffer sbWhereClause = new StringBuffer("PARTY.isActive = true AND ");

		if (tbMemberName.getText() != null && tbMemberName.getText().length() > 0)
			sbWhereClause.append("PARTY.name like '%").append(tbMemberName.getText()).append("%' AND ");

		if (tbKeyWords.getText() != null && tbKeyWords.getText().length() > 0)
			sbWhereClause.append("PARTY.keywords like '%").append(tbKeyWords.getText()).append("%' AND ");

		if (sbBusinessCategory.getText() != null && sbBusinessCategory.getText().length() > 0)
			sbWhereClause.append("BUSINESSCATEGORY.name = '").append(sbBusinessCategory.getText()).append("' AND ");

		if (sbLocation.getText() != null && sbLocation.getText().length() > 0)
			sbWhereClause.append("PARTYCONTACT.area like '%").append(sbLocation.getText()).append("%' AND ");

		if (sbWhereClause.length() > 5) {
			return sbWhereClause.substring(0, sbWhereClause.length() - 4).toString();
		}

		return "";
	}

	private void populateArea(final MultiWordSuggestOracle mwsOracle, final String cityName, final SuggestBox suggestBox, final String areaName) {
		mwsOracle.clear();
		ServiceUtil.getHibernateServiceAsync().findObjects("AREA", new String[] { "areaName" }, "cityName='" + cityName + "'", "areaName", false, true, new AsyncCallback() {

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Populate Area:"+caught.getLocalizedMessage());

			}

			@Override
			public void onSuccess(Object result) {
				List dataList = (List) result;
				mwsOracle.addAll(dataList);

				if (suggestBox != null)
					suggestBox.setValue(areaName);
			}
		});
	}

	private void populateBusinessCategory(final MultiWordSuggestOracle bcMWSuggestOracle) {
		ServiceUtil.getHibernateServiceAsync().findObjects("BUSINESSCATEGORY", new String[] { "name" }, "isActive=true", "name", false, true, new AsyncCallback() {

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("populateBusinessCategory"+caught.getLocalizedMessage());

			}

			@Override
			public void onSuccess(Object result) {
				List dataList = (List) result;
				bcMWSuggestOracle.addAll(dataList);

			}
		});
	}

	private void addTopMenus() {

		Anchor mnuHome = new Anchor("HOME");
		mnuHome.setStyleName("topMenuOrangeLnk");
		topMenuTable.setWidget(0, 0, mnuHome);
		addHyperlinkClickListener(mnuHome, true);
		topMenuTable.setWidget(0, 1, getEmptyHTML());
		Anchor mnuFindBus = new Anchor("FIND BUSINESS");
		mnuFindBus.setStyleName("topMenuBlueLnk");
		topMenuTable.setWidget(0, 2, mnuFindBus);
		addHyperlinkClickListener(mnuFindBus, true);
		topMenuTable.setWidget(0, 3, getEmptyHTML());
		Anchor mnuAddBus = new Anchor("ADD BUSINESS");
		mnuAddBus.setStyleName("topMenuBlueLnk");
		topMenuTable.setWidget(0, 4, mnuAddBus);
		addHyperlinkClickListener(mnuAddBus, true);
		topMenuTable.setWidget(0, 5, getEmptyHTML());
		Anchor mnuProfile = new Anchor("MY PROFILE");
		mnuProfile.setStyleName("topMenuBlueLnk");
		topMenuTable.setWidget(0, 6, mnuProfile);
		addHyperlinkClickListener(mnuProfile, true);
		topMenuTable.setWidget(0, 7, getEmptyHTML());
		Anchor mnuAboutUs = new Anchor("ABOUT US");
		mnuAboutUs.setStyleName("topMenuBlueLnk");
		topMenuTable.setWidget(0, 8, mnuAboutUs);
		addHyperlinkClickListener(mnuAboutUs, true);
		topMenuTable.setWidget(0, 9, getEmptyHTML());
		Anchor mnuContactUs = new Anchor("CONTACT US");
		mnuContactUs.setStyleName("topMenuBlueLnk");
		topMenuTable.setWidget(0, 10, mnuContactUs);
		addHyperlinkClickListener(mnuContactUs, true);

		topMenuTable.getFlexCellFormatter().setStyleName(0, 0, "menubg1");
		topMenuTable.getFlexCellFormatter().setStyleName(0, 2, "menubg");
		topMenuTable.getFlexCellFormatter().setStyleName(0, 4, "menubg");
		topMenuTable.getFlexCellFormatter().setStyleName(0, 6, "menubg");
		topMenuTable.getFlexCellFormatter().setStyleName(0, 8, "menubg");
		topMenuTable.getFlexCellFormatter().setStyleName(0, 10, "menubg");

		topMenuTable.getFlexCellFormatter().setWidth(0, 0, "110px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 2, "108px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 4, "108px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 6, "108px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 8, "108px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 10, "108px");

		topMenuTable.getFlexCellFormatter().setHeight(0, 0, "30px");
		topMenuTable.getFlexCellFormatter().setHeight(0, 2, "30px");
		topMenuTable.getFlexCellFormatter().setHeight(0, 4, "30px");
		topMenuTable.getFlexCellFormatter().setHeight(0, 6, "30px");
		topMenuTable.getFlexCellFormatter().setHeight(0, 8, "30px");
		topMenuTable.getFlexCellFormatter().setHeight(0, 10, "30px");

		topMenuTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		topMenuTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
		topMenuTable.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
		topMenuTable.getFlexCellFormatter().setHorizontalAlignment(0, 6, HasHorizontalAlignment.ALIGN_CENTER);
		topMenuTable.getFlexCellFormatter().setHorizontalAlignment(0, 8, HasHorizontalAlignment.ALIGN_CENTER);
		topMenuTable.getFlexCellFormatter().setHorizontalAlignment(0, 10, HasHorizontalAlignment.ALIGN_CENTER);

		topMenuTable.getFlexCellFormatter().setWidth(0, 1, "2px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 3, "2px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 5, "2px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 7, "2px");
		topMenuTable.getFlexCellFormatter().setWidth(0, 9, "2px");
	}

	private void addBottomMenus(FlexTable menuTable) {

		Anchor mnuFindBus = new Anchor("Find Business");
		menuTable.setWidget(0, 0, mnuFindBus);
		addHyperlinkClickListener(mnuFindBus, false);
		menuTable.setWidget(0, 1, getEmptyHTML());
		menuTable.setWidget(0, 2, new HTML("|"));
		menuTable.setWidget(0, 3, getEmptyHTML());

		Anchor mnuAddBus = new Anchor("Add Business");
		menuTable.setWidget(0, 4, mnuAddBus);
		addHyperlinkClickListener(mnuAddBus, false);
		menuTable.setWidget(0, 5, getEmptyHTML());
		menuTable.setWidget(0, 6, new HTML("|"));
		menuTable.setWidget(0, 7, getEmptyHTML());

		Anchor mnuProfile = new Anchor("My Profile");
		menuTable.setWidget(0, 8, mnuProfile);
		addHyperlinkClickListener(mnuProfile, false);
		menuTable.setWidget(0, 9, getEmptyHTML());
		menuTable.setWidget(0, 10, new HTML("|"));
		menuTable.setWidget(0, 11, getEmptyHTML());

		Anchor mnuAboutUs = new Anchor("About Us");
		menuTable.setWidget(0, 12, mnuAboutUs);
		addHyperlinkClickListener(mnuAboutUs, false);
		menuTable.setWidget(0, 13, getEmptyHTML());
		menuTable.setWidget(0, 14, new HTML("|"));
		menuTable.setWidget(0, 15, getEmptyHTML());

		Anchor mnuContactUs = new Anchor("Contact Us");
		menuTable.setWidget(0, 16, mnuContactUs);
		addHyperlinkClickListener(mnuContactUs, false);

		HTML copyRightHTML = new HTML("Copyright &copy; 2012 <span class=\"body_txt_blue\"><b>PBL</b></span>.All Rights Reserved.");
		menuTable.setWidget(1, 0, copyRightHTML);

		menuTable.getFlexCellFormatter().setStyleName(0, 0, "hyperLnk");
		menuTable.getFlexCellFormatter().setStyleName(0, 4, "hyperLnk");
		menuTable.getFlexCellFormatter().setStyleName(0, 8, "hyperLnk");
		menuTable.getFlexCellFormatter().setStyleName(0, 12, "hyperLnk");
		menuTable.getFlexCellFormatter().setStyleName(0, 16, "hyperLnk");

		menuTable.getFlexCellFormatter().setStyleName(0, 2, "body_txt_blue1");
		menuTable.getFlexCellFormatter().setStyleName(0, 6, "body_txt_blue1");
		menuTable.getFlexCellFormatter().setStyleName(0, 10, "body_txt_blue1");
		menuTable.getFlexCellFormatter().setStyleName(0, 14, "body_txt_blue1");

		menuTable.getFlexCellFormatter().setHeight(0, 0, "20px");
		menuTable.getFlexCellFormatter().setHeight(1, 0, "20px");

		menuTable.getFlexCellFormatter().setWidth(0, 0, "60px");
		menuTable.getFlexCellFormatter().setWidth(0, 4, "60px");
		menuTable.getFlexCellFormatter().setWidth(0, 8, "40px");
		menuTable.getFlexCellFormatter().setWidth(0, 12, "40px");
		menuTable.getFlexCellFormatter().setWidth(0, 16, "30px");

		menuTable.getFlexCellFormatter().setWidth(0, 2, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 6, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 10, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 14, "2px");

		menuTable.getFlexCellFormatter().setWidth(0, 1, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 3, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 5, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 7, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 9, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 11, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 13, "2px");
		menuTable.getFlexCellFormatter().setWidth(0, 15, "2px");

		menuTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		menuTable.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
		menuTable.getFlexCellFormatter().setHorizontalAlignment(0, 8, HasHorizontalAlignment.ALIGN_CENTER);
		menuTable.getFlexCellFormatter().setHorizontalAlignment(0, 12, HasHorizontalAlignment.ALIGN_CENTER);
		menuTable.getFlexCellFormatter().setHorizontalAlignment(0, 16, HasHorizontalAlignment.ALIGN_CENTER);

		menuTable.getFlexCellFormatter().setColSpan(1, 0, 17);
		menuTable.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
	}

	private HTML getEmptyHTML() {
		return new HTML("&nbsp;");
	}

	private void addImages(final FlexTable hpImages, final Image leftImage, final Image rightImage, final String fileFolder, final int noOfImages, final String imageHeight, final String imageWidth) {
//		ServiceUtil.getUserLoginServiceAsync().getImages("/UploadFile/" + fileFolder, new AsyncCallback() {
//
//			@Override
//			public void onFailure(Throwable caught) {
//				Window.alert("addImages:"+caught.getLocalizedMessage());
//
//			}
//
//			@Override
//			public void onSuccess(Object result) {
				String header = "<marquee scrollamount=\"8\" direction=\"left\" loop=\"true\" height=\"60px\" width=\"900px\" >";
				String footer = "</marquee>";
//				g
				final Map dataMap = (Map) getFiles("/UploadFile/" + fileFolder);

				final Integer rowSize = dataMap.size() / noOfImages;

				leftImage.setLayoutData(0);
				rightImage.setLayoutData(1);

				leftImage.addClickHandler(new ClickHandler() {

					@Override
					public void onClick(ClickEvent event) {
						Integer imageIndex = (Integer) leftImage.getLayoutData();

						if (imageIndex >= 0) {
							String firstImageURL = (String) dataMap.get((imageIndex * noOfImages) + 1);
							if (firstImageURL != null && firstImageURL.trim().length() > 0) {
								Image image1 = new Image(firstImageURL);
								image1.setLayoutData(firstImageURL);
								image1.setHeight(imageHeight);
								image1.setWidth(imageWidth);
								hpImages.setWidget(0, 1, image1);
								addImageClickHandler(image1);
							}

							if (fileFolder.equalsIgnoreCase("BusinessImages")) {

								String secondImageURL = (String) dataMap.get((imageIndex * noOfImages) + 2);

								if (secondImageURL != null && secondImageURL.trim().length() > 0) {
									Image image2 = new Image(secondImageURL);
									image2.setLayoutData(secondImageURL);
									image2.setHeight(imageHeight);
									image2.setWidth(imageWidth);
									hpImages.setWidget(0, 3, image2);
									addImageClickHandler(image2);
								}
								String thirdImageURL = (String) dataMap.get((imageIndex * noOfImages) + 3);
								if (thirdImageURL != null && thirdImageURL.trim().length() > 0) {
									Image image3 = new Image(thirdImageURL);
									image3.setLayoutData(thirdImageURL);
									image3.setHeight(imageHeight);
									image3.setWidth(imageWidth);
									hpImages.setWidget(0, 5, image3);
									addImageClickHandler(image3);
								}
							}
							rightImage.setLayoutData(imageIndex + 1);
							leftImage.setLayoutData(imageIndex - 1);
						}

					}
				});

				rightImage.addClickHandler(new ClickHandler() {

					@Override
					public void onClick(ClickEvent event) {
						Integer imageIndex = (Integer) rightImage.getLayoutData();
						if (imageIndex > 0 && imageIndex <= rowSize) {

							String firstImageURL = (String) dataMap.get((imageIndex * noOfImages) + 1);
							if (firstImageURL != null && firstImageURL.trim().length() > 0) {
								Image image1 = new Image(firstImageURL);
								image1.setLayoutData(firstImageURL);
								image1.setHeight(imageHeight);
								image1.setWidth(imageWidth);
								hpImages.setWidget(0, 1, image1);
								addImageClickHandler(image1);
							}
							if (fileFolder.equalsIgnoreCase("BusinessImages")) {

								String secondImageURL = (String) dataMap.get((imageIndex * noOfImages) + 2);

								if (secondImageURL != null && secondImageURL.trim().length() > 0) {
									Image image2 = new Image(secondImageURL);
									image2.setLayoutData(secondImageURL);
									image2.setHeight(imageHeight);
									image2.setWidth(imageWidth);
									hpImages.setWidget(0, 3, image2);
									addImageClickHandler(image2);
								}
								String thirdImageURL = (String) dataMap.get((imageIndex * noOfImages) + 3);
								if (thirdImageURL != null && thirdImageURL.trim().length() > 0) {
									Image image3 = new Image(thirdImageURL);
									image3.setLayoutData(thirdImageURL);
									image3.setHeight(imageHeight);
									image3.setWidth(imageWidth);
									hpImages.setWidget(0, 5, image3);
									addImageClickHandler(image3);
								}
							}
							leftImage.setLayoutData(imageIndex - 1);
							rightImage.setLayoutData(imageIndex + 1);

						}

					}
				});
				System.err.println("(String) dataMap.get(1)"+(String) dataMap.get(1));
				Image image1 = new Image((String) dataMap.get(1));
				image1.setLayoutData((String) dataMap.get(1));
				hpImages.setWidget(0, 1, image1);
				image1.setHeight(imageHeight);
				image1.setWidth(imageWidth);
				addImageClickHandler(image1);
				if (fileFolder.equalsIgnoreCase("BusinessImages")) {
					Image image2 = new Image((String) dataMap.get(2));
					image2.setLayoutData((String) dataMap.get(2));
					image2.setHeight(imageHeight);
					image2.setWidth(imageWidth);
					hpImages.setWidget(0, 3, image2);
					addImageClickHandler(image2);

					Image image3 = new Image((String) dataMap.get(3));
					image3.setLayoutData((String) dataMap.get(3));
					image3.setHeight(imageHeight);
					image3.setWidth(imageWidth);
					hpImages.setWidget(0, 5, image3);
					addImageClickHandler(image3);
				}

//			}
		//});

	}
	
	private Map getFiles(String directoryName) {
		Map<Integer,String> fileMap = new HashMap<Integer,String>();
		if (directoryName.contains("BusinessImages")) {
			fileMap.put(1,"./UploadFile/BusinessImages/architects drawings.jpg");
			fileMap.put(2,"./UploadFile/BusinessImages/architects.jpg");
			fileMap.put(3,"./UploadFile/BusinessImages/building pictures1.jpg");
			fileMap.put(4,"./UploadFile/BusinessImages/cable tray.jpg");
			fileMap.put(5,"./UploadFile/BusinessImages/cement.jpg");
			fileMap.put(6,"./UploadFile/BusinessImages/centering equipments.jpg");
			fileMap.put(7,"./UploadFile/BusinessImages/civil engineers.jpg");
			fileMap.put(8,"./UploadFile/BusinessImages/earthmovers.jpg");
			fileMap.put(9,"./UploadFile/BusinessImages/fire protection equipments.jpg");
			fileMap.put(10,"./UploadFile/BusinessImages/flyash bricks.jpg");
			fileMap.put(11,"./UploadFile/BusinessImages/hollow blocks.jpg");
			fileMap.put(12,"./UploadFile/BusinessImages/interior_designers.jpg");
			fileMap.put(13,"./UploadFile/BusinessImages/landscape architects.jpg");
			fileMap.put(14,"./UploadFile/BusinessImages/landscape_design.jpg");
			fileMap.put(15,"./UploadFile/BusinessImages/lifts1.jpg");
			fileMap.put(16,"./UploadFile/BusinessImages/modular kitchen.jpg");
			fileMap.put(17,"./UploadFile/BusinessImages/nursery.jpg");
			fileMap.put(18,"./UploadFile/BusinessImages/scaffolding manufactures.jpg");
			fileMap.put(19,"./UploadFile/BusinessImages/security system.jpg");
			fileMap.put(20,"./UploadFile/BusinessImages/soil testing.jpg");
			fileMap.put(21,"./UploadFile/BusinessImages/stainless steel fabrications.jpg");
			fileMap.put(22,"./UploadFile/BusinessImages/structural_glazing_cladding.jpg");
			fileMap.put(23,"./UploadFile/BusinessImages/surveying instruments.jpg");
			fileMap.put(24,"./UploadFile/BusinessImages/surveyors land.jpg");
			fileMap.put(25,"./UploadFile/BusinessImages/water proofing.jpg");
		}else{
			fileMap.put(1,"./UploadFile/PreviousDirectory/Wrapper_2003.jpg");
			fileMap.put(2,"./UploadFile/PreviousDirectory/Wrapper_2004.jpg");
			fileMap.put(3,"./UploadFile/PreviousDirectory/Wrapper_2005.jpg");
			fileMap.put(4,"./UploadFile/PreviousDirectory/Wrapper_2006.jpg");
			fileMap.put(5,"./UploadFile/PreviousDirectory/Wrapper_2007.jpg");
			fileMap.put(6,"./UploadFile/PreviousDirectory/Wrapper_2008.jpg");
			fileMap.put(7,"./UploadFile/PreviousDirectory/Wrapper_2009.jpg");
			fileMap.put(8,"./UploadFile/PreviousDirectory/Wrapper_2010.jpg");
			fileMap.put(9,"./UploadFile/PreviousDirectory/Wrapper_2011.jpg");
			fileMap.put(10,"./UploadFile/PreviousDirectory/Wrapper_2012.jpg");
		}
		
		return fileMap;
	}



	private void addImageClickHandler(final Image thumbNailImage) {
		thumbNailImage.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				String mediaSource = (String) thumbNailImage.getLayoutData();
				PopupPanel popup = new PopupPanel(true);
				// popup.setStyleName("modal");
				Image img = new Image(mediaSource);
				img.setPixelSize(560, 500);
				popup.add(img);
				popup.setGlassEnabled(true);
				popup.center();
				popup.show();

			}
		});

	}

	private void addHyperlinkClickListener(final Anchor anchor, final boolean isTab) {
		anchor.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (isTab)
					changeAnchorStyle(anchor);

				FlexTable mainTable = (FlexTable) RootPanel.get("mainContainer").getWidget(0);
				mainTable.clear();
				mainTable.setWidth("960px");
				if (anchor.getHTML().equalsIgnoreCase("Home")){
					addMainContainter(mainTable);
				}if (anchor.getHTML().equalsIgnoreCase("About Us")) {

					FlexTable aboutUsTable = new FlexTable();
					aboutUsTable.setStyleName("left_blue_box");
					aboutUsTable.setWidth("660px");
					aboutUsTable.setHeight("607px");
					aboutUsTable.setWidget(0, 0, new Image("./images/about_img.jpg"));
					
					
					
					FlexTable ftLeftBlue = new FlexTable();
					ftLeftBlue.setStyleName("left_blue_box");
					ftLeftBlue.setWidth("334px");
					ftLeftBlue.setHeight("450px");

					ftLeftBlue.setWidget(0, 0, new HTML("<pre></pre>We are pleased to introduce ourselves as publishers of <B>PROFESSIONAL BUILDERS\' DIRECTORY</B> for Chennai."));
					ftLeftBlue.setWidget(1, 0, new HTML("<pre></pre>Ten volumes of Professional Builders\' Directory of Chennai received good response from all the Building Professionals and the General Public. It serves as their basic source for acquiring vital information regarding Building Professionals and various Building Material Manufacturers and suppliers in Chennai city."));
					ftLeftBlue.setWidget(2, 0, new HTML("<pre></pre>Information regarding various Building Professionals like Architects, Builders,Civil Contractors, Structural Engineers, Interior Designers, Electrical Contractors,Plumbing Contractors etc., is also updated elaborately in our Builders\' Directory."));
					ftLeftBlue.setWidget(3, 0, new HTML("<pre></pre>To give a maximum benefit to all our advertisers, Professional Builders\' Directory is freely distributed to Architects, Builders, Civil Contractors, Interior Designers, Building professionals, Building Material suppliers and to all the personswho are related with construction industry in Chennai. It is also freely circulated to all the Construction sites in Chennai.."));
					ftLeftBlue.setWidget(4, 0, new HTML("<pre></pre>As it reaches to all your prospective customers in Chennai and referred at every phase in Construction industry, it will give you more benefits to your business."));
					ftLeftBlue.getFlexCellFormatter().setStyleName(0, 0, "body_txt_black1");
					ftLeftBlue.getFlexCellFormatter().setStyleName(1, 0, "body_txt_black1");
					ftLeftBlue.getFlexCellFormatter().setStyleName(2, 0, "body_txt_black1");
					ftLeftBlue.getFlexCellFormatter().setStyleName(3, 0, "body_txt_black1");
					ftLeftBlue.getFlexCellFormatter().setStyleName(4, 0, "body_txt_black1");
					aboutUsTable.setWidget(0, 1, ftLeftBlue);
					

					FlexTable hpBusinessImages = new FlexTable();
					// hpBusinessImages.setWidth("250px");
					hpBusinessImages.setStyleName("left_blue_box1");
					hpBusinessImages.setHeight("300px");
					hpBusinessImages.setWidth("200px");
					aboutUsTable.setWidget(1, 0, hpBusinessImages);

					Image leftImage = new Image("./images/left_arrow_02.gif");
					Image rightImage = new Image("./images/right_arrow_01.gif");
					FlexTable childBusinessTable = new FlexTable();
					childBusinessTable.setWidget(0, 0, leftImage);
					childBusinessTable.setWidget(0, 1, new HTML());
					childBusinessTable.setWidget(0, 2, new HTML());
					childBusinessTable.setWidget(0, 3, rightImage);

					hpBusinessImages.setWidget(0, 0, childBusinessTable);
					childBusinessTable.setWidth("200px");

					childBusinessTable.getFlexCellFormatter().setStyleName(0, 1, "Prem_AD_box");

					childBusinessTable.getFlexCellFormatter().setWidth(0, 2, "15x");
					addImages(childBusinessTable, leftImage, rightImage, "PreviousDirectory", 1, "300px", "200px");

					mainTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
					mainTable.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
					mainTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
					mainTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);

					mainTable.setWidget(0, 1, aboutUsTable);
					aboutUsTable.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
					aboutUsTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);
					aboutUsTable.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
					aboutUsTable.getFlexCellFormatter().setWidth(1, 0, "250px");
					aboutUsTable.getFlexCellFormatter().setRowSpan(0, 1, 2);
					mainTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
					// addMainContainter(mainTable);
				}

				else if (anchor.getHTML().equalsIgnoreCase("Contact Us")) {

					FlexTable contactUsTable = new FlexTable();
					contactUsTable.setStyleName("left_blue_box");
					contactUsTable.setWidth("660px");
					contactUsTable.setHeight("607px");
					contactUsTable.setWidget(0, 0, new Image("./images/contact_img.jpg"));
					mainTable.setWidget(0, 1, contactUsTable);

					String address = "<P> 36, Sri Ram Nagar Main Road,<br> Pallipattu , Tharamani, <br>Chennai - 600 113.</P>";
					String phone = "044-6529 1930 / 2235 0986";
					String mobile = "+91 98405 69019 / 9283117986";
					String email = "subramanianpbl@yahoo.co.in , vj.rubesh@gmail.com";
					FlexTable centerContentTable = new FlexTable();
					centerContentTable.setWidget(0, 0, new HTML("PROFESSIONAL BUSINESS LINE"));
					centerContentTable.setWidget(1, 0, new Image("./images/company_icon.png"));
					centerContentTable.getFlexCellFormatter().setStyleName(0, 0, "heading_blue_s1");
					centerContentTable.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);

					if (address != null && address.trim().length() > 0) {
						centerContentTable.setWidget(1, 1, new HTML(address));
						centerContentTable.getFlexCellFormatter().setStyleName(1, 1, "body_txt_black");

					}
					if (phone != null && phone.trim().length() > 0) {
						int rowCount = centerContentTable.getRowCount();
						centerContentTable.setWidget(rowCount, 0, new Image("./images/phone_icon.png"));
						centerContentTable.setWidget(rowCount, 1, new HTML(phone));
						centerContentTable.getFlexCellFormatter().setStyleName(rowCount, 1, "body_txt_black");

					}

					if (mobile != null && mobile.trim().length() > 0) {
						int rowCount = centerContentTable.getRowCount();
						centerContentTable.setWidget(rowCount, 0, new Image("./images/mobile_icon.png"));
						centerContentTable.setWidget(rowCount, 1, new HTML(mobile));
						centerContentTable.getFlexCellFormatter().setStyleName(rowCount, 1, "body_txt_black");
					}

					if (email != null && email.trim().length() > 0) {
						int rowCount = centerContentTable.getRowCount();
						centerContentTable.setWidget(rowCount, 0, new Image("./images/email_icon.png"));
						String[] emailArray = email.split(",");
						StringBuffer sbEmail = new StringBuffer("<span>");

						if (emailArray.length == 0)
							sbEmail.append("<a href=\"mailto:" + email + "\" class=\"hyperLnk1\">" + email + "</a>");
						for (int index = 0; index < emailArray.length; index++) {
							sbEmail.append("<a href=\"mailto:" + emailArray[index] + "\" class=\"hyperLnk1\">" + emailArray[index] + "</a>");
							if (index < emailArray.length - 1)
								sbEmail.append(",");
						}
						sbEmail.append("</span>");
						centerContentTable.setWidget(rowCount, 1, new HTML(sbEmail.toString()));
					}

					centerContentTable.getFlexCellFormatter().setColSpan(0, 0, 2);
					contactUsTable.setWidget(0, 1, centerContentTable);

					contactUsTable.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);

					contactUsTable.getFlexCellFormatter().setHeight(0, 1, "300px");
					contactUsTable.getFlexCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);
					final HorizontalPanel hp = new HorizontalPanel();
					contactUsTable.setWidget(1, 0, hp);
					contactUsTable.getFlexCellFormatter().setColSpan(1, 0, 2);
					contactUsTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
					googlePopup = new GoogleMap("600px", "250px", "36, Sri Ram Nagar Main Road, Pallipattu , Tharamani, Chennai", null, null, new AsyncCallback() {

						@Override
						public void onFailure(Throwable caught) {
							// TODO Auto-generated method stub

						}

						@Override
						public void onSuccess(Object result) {
							hp.clear();
							hp.add(googlePopup);
						}
					});

					mainTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
				}
//				else if (anchor.getHTML().equalsIgnoreCase("My Profile")) {
//					mainTable.setWidget(0, 0, new AlbumViewer(48L));
//				}

			}
		});
	}

	private void changeAnchorStyle(Anchor selectedAnchor) {
		int cellCount = topMenuTable.getCellCount(0);
		for (int index = 0; index < cellCount; index++) {
			Widget widget = topMenuTable.getWidget(0, index);
			if (widget instanceof Anchor) {
				Anchor anchor = (Anchor) widget;
				anchor.removeStyleName(anchor.getStyleName());
				topMenuTable.getFlexCellFormatter().removeStyleName(0, index, topMenuTable.getFlexCellFormatter().getStyleName(0, index));

				if (anchor.getText().equalsIgnoreCase(selectedAnchor.getText())) {
					anchor.setStyleName("topMenuOrangeLnk");
					topMenuTable.getFlexCellFormatter().setStyleName(0, index, "menubg1");
				} else {
					topMenuTable.getFlexCellFormatter().setStyleName(0, index, "menubg");
					anchor.setStyleName("topMenuBlueLnk");
				}
			}

		}
	}
}
